/* craco.config.js 用于修改默认配置 */

// 待安装
// https://day.js.org/
// @babel/plugin-proposal-decorators
// babel-plugin-import
// react-loadable
// styled-components
// classnames

// 需要用到类似 less-loader 提供的 less 变量覆盖功能
const CracoLessPlugin = require('craco-less');
const { resolve } = require('path');
const { when, whenDev, whenProd, whenTest, ESLINT_MODES, POSTCSS_MODES } = require("@craco/craco");

// 没生效
const proxyConfig = {
  // 配置多个代理,
  '/hybrid': {
    target: 'https://cnodejs.org/api/v1',
    ws: true,
    changeOrigin: true,
    pathRewrite: {
      "^/cnode": "/"
    }
  }
};

module.exports = {
  reactScriptsVersion: "react-scripts" /* (default value) */,
  style: {
    modules: {
      localIdentName: ""
    },
    // css: {
    //   loaderOptions: { /* Any css-loader configuration options: https://github.com/webpack-contrib/css-loader. */ },
    //   loaderOptions: (cssLoaderOptions, { env, paths }) => { return cssLoaderOptions; }
    // },
    // sass: {
    //   loaderOptions: { /* Any sass-loader configuration options: https://github.com/webpack-contrib/sass-loader. */ },
    //   loaderOptions: (sassLoaderOptions, { env, paths }) => { return sassLoaderOptions; }
    // },
    // postcss: {
    //   mode: "extends" /* (default value) */ || "file",
    //   plugins: [],
    //   env: {
    //     autoprefixer: { /* Any autoprefixer options: https://github.com/postcss/autoprefixer#options */ },
    //     stage: 3, /* Any valid stages: https://cssdb.org/#staging-process. */
    //     features: { /* Any CSS features: https://preset-env.cssdb.org/features. */ }
    //   },
    //   loaderOptions: { /* Any postcss-loader configuration options: https://github.com/postcss/postcss-loader. */ },
    //   loaderOptions: (postcssLoaderOptions, { env, paths }) => { return postcssLoaderOptions; }
    // }
  },
  // eslint: {
  //   enable: true /* (default value) */,
  //   mode: "extends" /* (default value) */ || "file",
  //   configure: { /* Any eslint configuration options: https://eslint.org/docs/user-guide/configuring */ },
  //   configure: (eslintConfig, { env, paths }) => { return eslintConfig; },
  //   loaderOptions: { /* Any eslint-loader configuration options: https://github.com/webpack-contrib/eslint-loader. */ },
  //   loaderOptions: (eslintOptions, { env, paths }) => { return eslintOptions; }
  // },
  babel: {
    presets: [],
    plugins: [],
    loaderOptions: { /* Any babel-loader configuration options: https://github.com/babel/babel-loader. */ },
    loaderOptions: (babelLoaderOptions, { env, paths }) => { return babelLoaderOptions; }
  },
  typescript: {
    enableTypeChecking: true /* (default value)  */
  },
  webpack: {
    alias: {
      '@': resolve('src')
    },
    plugins: [],
    configure: { /* Any webpack configuration options: https://webpack.js.org/configuration */ },
    configure: (webpackConfig, { env, paths }) => { return webpackConfig; }
  },
  // jest: {
  //   babel: {
  //     addPresets: true, /* (default value) */
  //     addPlugins: true  /* (default value) */
  //   },
  //   configure: { /* Any Jest configuration options: https://jestjs.io/docs/en/configuration. */ },
  //   configure: (jestConfig, { env, paths, resolve, rootDir }) => { return jestConfig; }
  // },
  // devServer: { /* Any devServer configuration options: https://webpack.js.org/configuration/dev-server/#devserver. */ },
  devServer: (devServerConfig, { env, paths, proxy, allowedHost }) => { return devServerConfig; },
  plugins: [
    {
      plugin: CracoLessPlugin,
      options: {
        lessLoaderOptions: {
          lessOptions: {
            modifyVars: {
              '@primary-color': '#1DA57A',
              "@link-color": "#1DA57A",
              "@border-radius-base": "2px"
            },
            javascriptEnabled: true,
          },
        },
      },
    },
    {
      plugin: {
        overrideCracoConfig: ({ cracoConfig, pluginOptions, context: { env, paths } }) => { return cracoConfig; },
        overrideWebpackConfig: ({ webpackConfig, cracoConfig, pluginOptions, context: { env, paths } }) => { return webpackConfig; },
        overrideDevServerConfig: ({ devServerConfig, cracoConfig, pluginOptions, context: { env, paths, proxy, allowedHost } }) => { return devServerConfig; },
        // overrideJestConfig: ({ jestConfig, cracoConfig, pluginOptions, context: { env, paths, resolve, rootDir } }) => { return jestConfig },
      },
      options: {}
    }
  ]
};